﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class EditBranch : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["PinCode"]==null)
        {
            Response.Redirect("ViewBranches.aspx");
        }
        if (!DALBranch.CheckBranch(Request.QueryString["PinCode"]))
        {
            Response.Redirect("ViewBranches.aspx");
        }
    }
    protected void frmEditService_ItemCommand(object sender, FormViewCommandEventArgs e)
    {
        if (e.CommandName == "Edit")
        {
            frmEditService.DefaultMode = FormViewMode.Edit;
        }
        if (e.CommandName == "Update")
        {
            SubmitInformation();
            frmEditService.DefaultMode = FormViewMode.ReadOnly;
        }
        if (e.CommandName == "Cancel")
        {
            frmEditService.DefaultMode = FormViewMode.ReadOnly;
        }
    }
    private void SubmitInformation()
    {
        try
        {
            string pinCode = (frmEditService.FindControl("txtPincode") as TextBox).Text;
            string branchName = (frmEditService.FindControl("txtBranchName") as TextBox).Text;
            string branchAddress = (frmEditService.FindControl("txtBranchAddress") as TextBox).Text;
            string branhPhone = (frmEditService.FindControl("txtBranchPhone") as TextBox).Text;
            string branchFax = (frmEditService.FindControl("txtFax") as TextBox).Text;
            string cityID = (frmEditService.FindControl("ddlCityName") as DropDownList).SelectedValue;

            if (DALBranch.UpdateBranch(pinCode, branchAddress, branchName, branchFax, branhPhone, cityID))
            {
                lblMessage.Text = "<br/> <b>Update Successful</b>";
            }
            else
            {
                lblMessage.Text = "<br/> <b>Update Fail</b>";
            }
        }
        catch
        {
            lblMessage.Text = "<br/> <b>Update Fail</b>";
        }
    }
}
